package no.uio.ifi.cop.prover.cmp;

import java.util.Comparator;

import java.util.Random;

import no.uio.ifi.cop.prover.RuleMatcher;
import no.uio.ifi.cop.cl.Axiom;

/**
 * Randomly select which rules to pick first.
 *
 * NOTE: GOALRULES are respected, nothing precedes them
 * in the order of rules we try to match.
 *
 * @version 1.0
 * @author bjarneh@ifi.uio.no
 */

public class RandomOrder implements Comparator<RuleMatcher>{

    Random random;

    public RandomOrder(){
        this( System.currentTimeMillis() );
    }

    public RandomOrder(long seed){
        random = new Random( seed );
    }

    public int compare(RuleMatcher first, RuleMatcher second){

        if( first == second ){ return 0; }
        if( first.getId() == second.getId() ){ return 0; }
        if( first.getAxiom().getType() == Axiom.GOALRULE ){ return -1; }
        if( second.getAxiom().getType() == Axiom.GOALRULE ){ return 1; }

        return random.nextBoolean()? 1 : -1;
    }
}
